package org.fisco.bcos.evidence.gateway.config;

import lombok.Data;

import java.io.Serializable;

@SuppressWarnings("all")
@Data
public class ResultJson<T> implements Serializable {

    private static final long serialVersionUID = 783015033603078674L;
    private String code;
    private String msg;
    private String sign;
    private T data;

    public static ResultJson ok() {
        return ok(null, null);
    }

    public static ResultJson ok(Object o, String sign) {
        return new ResultJson(org.fisco.bcos.evidence.gateway.config.ResultCode.SUCCESS, o, sign);
    }

    public static ResultJson failure(org.fisco.bcos.evidence.gateway.config.ResultCode code) {
        return failure(code, null);
    }

    public static ResultJson failure(org.fisco.bcos.evidence.gateway.config.ResultCode code, Object o) {
        return new ResultJson(code, o, null);
    }

    public ResultJson(org.fisco.bcos.evidence.gateway.config.ResultCode resultCode) {
        setResultCode(resultCode);
    }

    public ResultJson(org.fisco.bcos.evidence.gateway.config.ResultCode resultCode, T data, String sign) {
        setResultCode(resultCode);
        this.data = data;
        this.sign = sign;
    }

    public void setResultCode(org.fisco.bcos.evidence.gateway.config.ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    @Override
    public String toString() {
        return "{" +
                "\"code\":" + "\"" + code + "\"" +
                ", \"msg\":\"" + msg + '\"' +
                ", \"sign\":\"" + sign + '\"' +
                ", \"data\":\"" + data + '\"' +
                '}';
    }

}
